﻿using DataAccessLayer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BussinessLogicLayer
{
    public class PhanQuyenBLL
    {
        static QuanLyGiaiDauDataContext QLGD = new QuanLyGiaiDauDataContext();
        public static List<Quyen> BatChucNang(int MaND)
        {
            var batchucnang = from pq in QLGD.PhanQuyens
                              from q in QLGD.Quyens
                              where pq.MaNguoiDung == MaND && pq.MaQuyen == q.MaQuyen && pq.KichHoat == true
                              select q;
            return batchucnang.ToList();
        }
        public static List<Quyen> LayQuyen()
        {
            var quyen = from q in QLGD.Quyens
                        select q;
            return quyen.ToList();
        }
        public static List<Quyen> LayMaQuyen(string TenQuyen)
        {
            var maquyen = from q in QLGD.Quyens
                          where q.TenQuyen == TenQuyen
                          select q;
            return maquyen.ToList();
        }
        public static bool PhanQuyen(PhanQuyen entity)
        {
            PhanQuyen pq = new PhanQuyen();
            pq.MaNguoiDung = entity.MaNguoiDung;
            pq.MaQuyen = entity.MaQuyen;
            pq.KichHoat = entity.KichHoat;
            QLGD.PhanQuyens.InsertOnSubmit(pq);
            QLGD.SubmitChanges();
            int kq = 1;
            return kq > 0;
        }
        public static bool XoaPhanQuyen(int MaND)
        {
            IQueryable<PhanQuyen> xoapq = from pq in QLGD.PhanQuyens where pq.MaNguoiDung == MaND select pq;
            QLGD.PhanQuyens.DeleteAllOnSubmit(xoapq);
            QLGD.SubmitChanges();
            int kq = 1;
            return kq > 0;
        }
    }
}
